//
//  MD5Encryption.m
//  com.yjwh.yj
//
//  Created by ferver7 on 2018/10/18.
//  Copyright © 2018年 ferver7. All rights reserved.
//

#import "MD5Encryption.h"
#import <CommonCrypto/CommonDigest.h>

//秘钥
static NSString *encryptionKey = @"DivJ6a5Gf@M0wxa5";

@implementation MD5Encryption

+ (NSString *)md5EncryptWithStringSrc:(NSString *)src andTimestamp :(NSString *)timestamp{
    return [self md5:[NSString stringWithFormat:@"%@%@%@", src,timestamp, encryptionKey]];
}
+(NSString *)md5EncryptSecret:(NSString *)phone andSecrt:(NSString *)secret
{
    return [self md5:[NSString stringWithFormat:@"%@%@%@", phone,secret, @"X7sRQzSXB24Jl@Mc"]];
}
+ (NSString *)md5:(NSString *)string{
    const char *cStr = [string UTF8String];
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    
    CC_MD5(cStr, (CC_LONG)strlen(cStr), digest);
    
    NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
        [result appendFormat:@"%02X", digest[i]];
    }
    
    return [result lowercaseString];
}


@end
